﻿//----------------------------------------------------------------
// Desc: 
// Edit: ShowLong, http://blog.csdn.net/showlong
//
// Date Created: 2009-10-13
//
// Update Date : 
//
// Copyright (c) Fuel4D (http://www.fuel4d.com), All rights reserved.
//
//----------------------------------------------------------------
#pragma once


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#define FUEL_MODULE_UI 1


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#pragma warning(disable:4819 4251 4275 4996 4786)


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#define FUEL_UI_USE_FLOAT       1           // UI系统的单位是符点数还是整型

#define FUEL_UI_RES_HEAD        0x52445546  // 'RDUF' UI资源库文件
#define FUEL_UI_RES_VER         2
#define FUEL_UI_RES_NAME        50          // UI资源名字长度
#define FUEL_UI_OBJ_NAME        40          // UI对象名字长度
#define FUEL_UI_FNT_NAME        128         // UI字体名字长度
#define FUEL_UI_DRAW_MAX        128         // UI系统中某些文本串长度
#define FUEL_UI_SUB_COUNT       80          // 容器对象的存放的子控件数量


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#ifdef WIN32
#define FCALL                   __stdcall
#define FCDECL                  __cdecl
#define FINLINE                 __forceinline
#ifdef _FUEL_EXPORTS
#define FAPI                    __declspec(dllexport)
#else
#define FAPI                    __declspec(dllimport)
#endif
#else
#define FCALL
#define FCDECL
#define FINLINE                 inline
#define FAPI
#endif

#define FVOLATILE               volatile


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#define _FTW(x)                 L##x
#define _FTA(x)                 x
#define _FNILW                  L""
#define _FNILA                  ""
#define _FENDW                  L'\0'
#define _FENDA                  '\0'

#define _FMACRO_COV(x)          _FTW(x)
#define _FFILEW_                _FMACRO_COV(__FILE__)
#define _FFUNCW_                _FMACRO_COV(__FUNCTION__)
#define _FLINEW_                __LINE__
#define _FDATEW_                _FMACRO_COV(__DATE__)
#define _FTIMEW_                _FMACRO_COV(__TIME__)

#define _FFILEA_                __FILE__
#define _FFUNCA_                __FUNCTION__
#define _FLINEA_                __LINE__
#define _FDATEA_                __DATE__
#define _FTIMEA_                __TIME__

#ifdef UNICODE
#define _FT                     _FTW
#define _FNIL                   _FNILW
#define _FEND                   _FENDW
#define _FFILE_                 _FFILEW_
#define _FFUNC_                 _FFUNCW_
#define _FLINE_                 _FLINEW_
#define _FDATE_                 _FDATEW_
#define _FTIME_                 _FTIMEW_
#else
#define _FT                     _FTA
#define _FNIL                   _FNILA
#define _FEND                   _FENDA
#define _FFILE_                 _FFILEA_
#define _FFUNC_                 _FFUNCA_
#define _FLINE_                 _FLINEA_
#define _FDATE_                 _FDATEA_
#define _FTIME_                 _FTIMEA_
#endif

#ifdef WIN32
#define _FFT                    _FTW
#define _FFNIL                  _FNILW
#define _FFEND                  _FENDW
#define _FFFILE_                _FFILEW_
#define _FFFUNC_                _FFUNCW_
#define _FFLINE_                _FLINEW_
#define _FFDATE_                _FDATEW_
#define _FFTIME_                _FTIMEW_
#else
#define _FFT                    _FTA
#define _FFNIL                  _FNILA
#define _FFEND                  _FENDA
#define _FFFILE_                _FFILEA_
#define _FFFUNC_                _FFUNCA_
#define _FFLINE_                _FLINEA_
#define _FFDATE_                _FDATEA_
#define _FFTIME_                _FTIMEA_
#endif

#define TRUE                    1
#define FALSE                   0
#define MAX_PATH                260
#define _MAX_PATH               260 /* max. length of full pathname */
#define _MAX_DRIVE              3   /* max. length of drive component */
#define _MAX_DIR                256 /* max. length of path component */
#define _MAX_FNAME              256 /* max. length of file name component */
#define _MAX_EXT                256 /* max. length of extension component */


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#if FUEL_UI_USE_FLOAT
typedef float                   funit;
#else
typedef int                     funit;
#endif

typedef char                    ACHAR;
typedef wchar_t                 WCHAR;
typedef unsigned long           FIDHASH;
typedef unsigned long long      FIDHASH64;
typedef int                     FTIME_T;

typedef char                    ACHAR;
typedef wchar_t                 WCHAR;
#ifdef UNICODE
typedef WCHAR                   TCHAR;
#else
typedef ACHAR                   TCHAR;
typedef unsigned short          DCHAR;
#endif
typedef TCHAR                   NCHAR;

typedef char                    CHAR;
typedef unsigned char           UCHAR;
typedef short                   SHORT;
typedef unsigned short          USHORT;
typedef int                     INT;
typedef unsigned int            UINT;
typedef long                    LONG;
typedef unsigned long           ULONG;
typedef long long               INT64;
typedef unsigned long long      UINT64;
typedef float                   FLOAT;
typedef double                  DOUBLE;

typedef signed char             SINT8;
typedef unsigned char           UINT8;
typedef signed short            SINT16;
typedef unsigned short          UINT16;
typedef signed int              SINT32;
typedef unsigned int            UINT32;
typedef signed long long        SINT64;

typedef unsigned char           BYTE;       // 单字节
typedef unsigned short          WORD;       // 双字节
typedef unsigned long           DWORD;      // 四字节
typedef unsigned long long      QWORD;      // 八字节

typedef int                     INT_PTR;
typedef unsigned int            UINT_PTR;
typedef long                    LONG_PTR;
typedef unsigned long           ULONG_PTR;
typedef unsigned long           DWORD_PTR;

typedef UINT_PTR                WPARAM;
typedef LONG_PTR                LPARAM;

typedef unsigned char           uchar;
typedef unsigned short          ushort;
typedef unsigned int            uint;
typedef unsigned long           ulong;
typedef unsigned long long      ulonglong;

typedef signed char             int8;
typedef unsigned char           uint8;
typedef signed short            int16;
typedef unsigned short          uint16;
typedef signed int              int32;
typedef unsigned int            uint32;
typedef signed long long        int64;
typedef unsigned long long      uint64;

#ifndef BOOL
typedef int                     BOOL;
#endif

#ifdef WIN32
typedef WCHAR                   FTCHAR;
typedef WCHAR                   FFCHAR;
#else
typedef ACHAR                   FTCHAR;
typedef ACHAR                   FFCHAR;
#endif

#ifdef _DEBUG
#define FUI_LIB(x)              x"D.lib"
#else
#define FUI_LIB(x)              x".lib"
#endif

enum EF_UI_ENCODE_MODE
{
    eUEM_ANSI,                      // WINDOWS 平台下默认多字节
    eUEM_UTF8,                      // ANDROID、LINUX 平台下默认多字节
    eUEM_UTF16LE,                   // WINDOWS 平台下默认宽字节
    eUEM_UTF16BE,                   // 大头的宽字节，不常用
    eUEM_UTF32LE,                   // ANDOIRD、LINUX 平台下默认宽字节
    eUEM_UTF32BE,

    eUEM_MAX,
};
#ifdef WIN32
#define FUEL_UI_ACHAR eUEM_ANSI
#define FUEL_UI_WCHAR eUEM_UTF16LE
#else
#define FUEL_UI_ACHAR eUEM_UTF8
#define FUEL_UI_WCHAR eUEM_UTF32LE
#endif


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#ifdef WIN32
#include <windows.h>
#include <tchar.h>
#endif
#ifdef ANDROID
#include <jni.h>
#include <sys/atomics.h>
#include <android/log.h>
#endif
#ifdef WIN32
#else
typedef void* HANDLE;
typedef HANDLE HWND;
#ifndef POINT_DEFINE
#define POINT_DEFINE
typedef struct tagPOINT
{
	LONG x;
	LONG y;
} 	POINT;
typedef struct tagRECT
{
	LONG left;
	LONG top;
	LONG right;
	LONG bottom;
} 	RECT;
typedef struct tagSIZE
{
	long        cx;
	long        cy;
} SIZE;
#endif
#endif
#include <stdlib.h>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <assert.h>
#include <malloc.h>
#include <sys/stat.h>


#include "UI/Base/FUI_RTTI.h"


//----------------------------------------------------------------
//
//----------------------------------------------------------------
// 字符串复制（支持中文，支持UNICODE和多字节，不支持UTF8）
// .size dst能容纳字符数量（不是内存大小）
// .cov_type 转换类型：0不转换，1转为小写，2转为大写（非英文字符不处理）
extern FAPI ACHAR* FUI_StrcpyA_s(ACHAR* dst, const ACHAR* src, size_t size, BYTE cov_type = 0);
extern FAPI WCHAR* FUI_StrcpyW_s(WCHAR* dst, const WCHAR* src, size_t size, BYTE cov_type = 0);
// 字符串比较
extern FAPI int FUI_StrcasecmpW(const WCHAR *s1, const WCHAR *s2);


//----------------------------------------------------------------
//
//----------------------------------------------------------------
template < typename _Ty >
FINLINE _Ty FUI_Max(_Ty a, _Ty b)
{
    return (a) > (b) ? (a) : (b);
}
template < typename _Ty >
FINLINE _Ty FUI_Min(_Ty a, _Ty b)
{
    return (a) < (b) ? (a) : (b);
}
FINLINE int FUI_StricmpW(const WCHAR* left, const WCHAR* right)
{
    if (left && right)
#ifdef WIN32
        return _wcsicmp(left, right);
#else
        return FUI_StrcasecmpW(left, right);
#endif
    return left ? 1 : -1;
}
FINLINE int FUI_StricmpA(const ACHAR* left, const ACHAR* right)
{
    if (left && right)
#ifdef WIN32
        return _stricmp(left, right);
#else
        return strcasecmp(left, right);
#endif
    return left ? 1 : -1;
}
FINLINE size_t FUI_StrlenW(const WCHAR* s)
{
    if (!s)
        return 0;
    size_t n = 0;
    while (*s)
        s++,n++;
    return n;
}
FINLINE size_t FUI_StrlenA(const ACHAR* s)
{
    if (s)
        return strlen(s);
    return 0;
}
FINLINE int FUI_StrcmpW(const WCHAR* left, const WCHAR* right)
{
    if (left && right)
        return wcscmp(left, right);
    return left ? 1 : -1;
}
FINLINE int FUI_StrcmpA(const ACHAR* left, const ACHAR* right)
{
    if (left && right)
        return strcmp(left, right);
    return left ? 1 : -1;
}
FINLINE int FUI_AtoiW(const WCHAR* str)
{
    if (!str)
        return 0;
#ifdef WIN32
    return _wtoi(str);
#else
    wchar_t* pend;
    return (int)wcstol(str, &pend, 10);
#endif
}
FINLINE int FUI_AtoiA(const ACHAR* str)
{
    if (!str)
        return 0;
    return atoi(str);
}
template < size_t size >
FINLINE ACHAR* FUI_StrcpyA(ACHAR (&dst)[size], const ACHAR* src, BYTE cov_type = 0)
{
    return FUI_StrcpyA_s(dst, src, size, cov_type);
}
template < size_t size >
FINLINE WCHAR* FUI_StrcpyW(WCHAR (&dst)[size], const WCHAR* src, BYTE cov_type = 0)
{
    return FUI_StrcpyW_s(dst, src, size, cov_type);
}


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#include "UI/Base/FUI_Template.h"
#include "UI/Base/FUI_InputVK.h"
#include "UI/Base/FUI_String.h"
#include "UI/Base/FUI_MemFile.h"
#include "UI/Base/FUI_ClassFactory.h"


//----------------------------------------------------------------
//
//----------------------------------------------------------------
// 从文件路径中找到文件名的位置
extern FAPI const WCHAR* FUI_FileNamePositionW(const WCHAR* szpath);
extern FAPI const ACHAR* FUI_FileNamePositionA(const ACHAR* szpath);
// 创建目录树，可以使用文件路径，包括子目录一起自动创建（如果路径全是目录，需在尾部加上\\）
extern FAPI void FUI_MakeDirectoryW(const WCHAR* szpath);
extern FAPI void FUI_MakeDirectoryA(const ACHAR* szpath);
// 生成字符串HASH
extern FAPI FIDHASH FUI_GetHashA(const ACHAR* szstr, bool make_lower = false);
extern FAPI FIDHASH FUI_GetHashW(const WCHAR* szstr, bool make_lower = false);
// UI编辑器列表菜单项与该项值互转函数
//   格式 %d(%d)，例 0(xxx)
#ifdef WIN32
extern FAPI void FUI_GetStringByIDW(WCHAR* szret, size_t count, const WCHAR* str, int id);
#endif
extern FAPI void FUI_GetStringByIDA(ACHAR* szret, size_t count, const ACHAR* str, int id);
extern FAPI int FUI_GetIDByStringW(const WCHAR* szstring);
extern FAPI int FUI_GetIDByStringA(const ACHAR* szstring);
// 格式化字符串，不支持多线程，不能嵌套
extern FAPI const WCHAR* FCALL FUI_StringFmtW(const WCHAR* fmt, ...);
extern FAPI const ACHAR* FCALL FUI_StringFmtA(const ACHAR* fmt, ...);
// 取文件大小
extern FAPI INT64 FUI_FileSizeW(const WCHAR* szpath);
extern FAPI INT64 FUI_FileSizeA(const ACHAR* szpath);
// 打开文件
extern FAPI FILE* FUI_OpenW(const WCHAR* filename, const WCHAR* mode);
extern FAPI FILE* FUI_OpenA(const ACHAR* filename, const ACHAR* mode);
extern FAPI size_t FUI_Write(const void* pSrcBuffer, size_t element_size, size_t element_count, FILE* file);
extern FAPI size_t FUI_Read(void* pDstBuffer, size_t element_size, size_t element_count, FILE* file);
extern FAPI int FUI_Seek(FILE* file, long offset, int origin);
extern FAPI int FUI_Close(FILE*& file);
// 获取当前逝去时间
extern FAPI DWORD FUI_GetTime();
// 原子加法
extern FAPI long FUI_InterlockedIncrement(long FVOLATILE *lpAddend);
// 原子减法
extern FAPI long FUI_InterlockedDecrement(long FVOLATILE *lpAddend);
// 获取字符集类型的字符串描述
extern FAPI const ACHAR* FUI_GetCharEncodeName(EF_UI_ENCODE_MODE em);
// 获取字符集类型对应的一个字符所点内存宽度
extern FAPI size_t FUI_GetCharEncodeSize(EF_UI_ENCODE_MODE em);
// 多字节与宽字节字符相互转换
// .src_em,dstem 各平台之间默认的编码模式
// .dst 输出后的尾部带有\0，字符串长度为取dst.size()-1
extern FAPI void FUI_WStrToAStr(const WCHAR* src, FV_UI_ACHAR& dst, EF_UI_ENCODE_MODE src_em = FUEL_UI_WCHAR, EF_UI_ENCODE_MODE dst_em = FUEL_UI_ACHAR);
extern FAPI void FUI_AStrToWStr(const ACHAR* src, FV_UI_WCHAR& dst, EF_UI_ENCODE_MODE src_em = FUEL_UI_ACHAR, EF_UI_ENCODE_MODE dst_em = FUEL_UI_WCHAR);
// 取得多字节与宽字节转换后所需的内存长度，
extern FAPI int FUI_WStrLength(const ACHAR* src);
extern FAPI int FUI_AStrLength(const WCHAR* src);
// 不安全的字符串转换，需要自己确保安全
extern FAPI void FUI_WStrToAStrNS(const WCHAR* src, ACHAR* dst);
extern FAPI void FUI_AStrToWStrNS(const ACHAR* src, WCHAR* dst);
// 将多字节字符串转为UTF8字符串，支持中文（GB2312 -> UTF8）
// .return 返回dst串
extern FAPI FUI_StringA& FUI_ANSIToUTF8(FUI_StringA& dst_utf8, FUI_StringA& src_ansi);
// 将UTF8字符串转为多字节字符串，支持中文（UTF8 -> GB2312）
// .return 返回dst串
extern FAPI FUI_StringA& FUI_UTF8ToANSI(FUI_StringA& dst_ansi, FUI_StringA& src_utf8);
// 从路径中定位文件名扩展名位置
// 返回位置，包括符号“.”，如果没有扩展名则返回0
extern FAPI const ACHAR* FUI_FileExtPosition(const ACHAR* szpath);
// 测试文件路径是否是指定扩展名，如果不是自动补充到该扩展名
// .ext 需要带上点，如“.png”、“.dds”
extern FAPI FUI_StringA& FUI_FileExtInspect(FUI_StringA& str, const ACHAR* ext);
// 在调试控制台打印一条信息，不作任何更改，直接打印（支持各平台和控制台）
extern FAPI void FUI_OutDebugStringW(const WCHAR* str);
extern FAPI void FUI_OutDebugStringA(const ACHAR* str);
extern FAPI void FUI_OutDebugMemory(void* p, size_t size, bool hex_mode = true, size_t line_nums = 32);
// 指定串区间的串长度
extern FAPI size_t FUI_StrnlenW(const WCHAR* wcs, size_t maxsize);
extern FAPI size_t FUI_StrnlenA(const ACHAR* str, size_t maxsize);
// 用于非WINDOWS系统的宽字符比较，忽略大小写
extern FAPI int FUI_StrcasecmpW(const WCHAR *s1, const WCHAR *s2);
extern FAPI int FUI_StrncasecmpW(const WCHAR *s1, const WCHAR *s2, size_t n);
// 将串转为大写
extern FAPI WCHAR* FUI_StrToUpperW(WCHAR* str);
extern FAPI ACHAR* FUI_StrToUpperA(ACHAR* str);
// 将串转为小写
extern FAPI WCHAR* FUI_StrToLowerW(WCHAR* str);
extern FAPI ACHAR* FUI_StrToLowerA(ACHAR* str);
// 字符大小写转换
// .cov_type 转换类型：0不转换，1转为小写，2转为大写（非英文字符不处理）
FINLINE WCHAR FUI_ConvertCharW(WCHAR k, BYTE cov_type = 0);
FINLINE ACHAR FUI_ConvertCharA(ACHAR k, BYTE cov_type = 0);


//----------------------------------------------------------------
// 错误编号
//----------------------------------------------------------------
enum EF_UI_ERROR_NO
{
    eUEN_OK,
    eUEN_NotFindFile,
    eUEN_LoadFileFail,
    eUEN_NotFindMuster,
    eUEN_NoDefaultFont,
    eUEN_NoDefaultPicture,
    eUEN_NoDefaultButton,
    eUEN_NoDefaultMenu,
    eUEN_AlignMode,
    eUEN_CreateWidget,
    eUEN_FileVer,
    eUEN_FileIsInt,
    eUEN_FileIsFloat,
    eUEN_IsInstance,
    eUEN_NotUIFile,

    EF_UI_ERROR_NO_FORCE = 0xFFFF,
};
extern FAPI const ACHAR* FUI_ErrorNoString(WORD wErrorId);


//----------------------------------------------------------------
// 图片的绘制模式
//----------------------------------------------------------------
enum EF_UI_DRAW_MODE
{
    eUDM_Normal_LT,                 // 普通左上
    eUDM_Normal_RT,                 // 普通右上
    eUDM_Normal_LB,                 // 普通左下
    eUDM_Normal_RB,                 // 普通右下
    eUDM_ExtendFull,                // 缩放拉伸
    eUDM_Fill_Four_Corner,          // 填充四角
    eUDM_Put_Left_Center,           // 放置左中
    eUDM_Put_Right_Center,          // 放置右中
    eUDM_Put_Top_Center,            // 放置上中
    eUDM_Put_Bottom_Center,         // 放置下中
    eUDM_Put_Center,                // 放置正中
    eUDM_Tiled_Normal,              // 平面平铺
    eUDM_Tiled_Horizontal,          // 横向平铺
    eUDM_Tiled_Vertical,            // 纵向平铺
    eUDM_Tiled_NinePAL,             // 九宫平铺
    eUDM_Tiled_H_Single,            // 单行横铺
    eUDM_Tiled_V_Single,            // 单行纵铺

    EF_UI_DRAW_MODE_FORCE = 0xFF,
};
#define FUI_DM_NORMAL_LT            _FTW("普通左上")
#define FUI_DM_NORMAL_RT            _FTW("普通右上")
#define FUI_DM_NORMAL_LB            _FTW("普通左下")
#define FUI_DM_NORMAL_RB            _FTW("普通右下")
#define FUI_DM_EXTENDFULL           _FTW("缩放拉伸")
#define FUI_DM_PUT_FOUR_CORNER      _FTW("填充四角")
#define FUI_DM_PUT_LEFT_CENTER      _FTW("放置左中")
#define FUI_DM_PUT_RIGHT_CENTER     _FTW("放置右中")
#define FUI_DM_PUT_TOP_CENTER       _FTW("放置上中")
#define FUI_DM_PUT_BOTTOM_CENTER    _FTW("放置下中")
#define FUI_DM_PUT_CENTER           _FTW("放置正中")
#define FUI_DM_TILED_NORMAL         _FTW("平面平铺")
#define FUI_DM_TILED_HORI           _FTW("横向平铺")
#define FUI_DM_TILED_VERT           _FTW("纵向平铺")
#define FUI_DM_TILED_NINEPAL        _FTW("九宫平铺")
#define FUI_DM_TILED_H_SINGLE       _FTW("单行横铺")
#define FUI_DM_TILED_V_SINGLE       _FTW("单行纵铺")
#define FUI_DM_CONTROL_COMBO        _FTW("普通左上|普通右上|普通左下|普通右下|缩放拉伸|填充四角|放置左中|放置右中|放置上中|放置下中|放置正中|平面平铺|横向平铺|纵向平铺|九宫平铺|单行横铺|单行纵铺|")
extern FAPI BYTE FUI_DrawModeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_DrawModeByEnum(BYTE eDrawMode);


//----------------------------------------------------------------
// 控件的排列模式
//----------------------------------------------------------------
enum EF_UI_ALIGN_MODE
{
    eUAM_LeftTop,                   // 左上
    eUAM_RightTop,                  // 右上
    eUAM_LeftBottom,                // 左下
    eUAM_RightBottom,               // 右下
    eUAM_Middle,                    // 居中
    eUAM_TopMiddle,                 // 上中
    eUAM_BottomMiddle,              // 下中
    eUAM_LeftMiddle,                // 左中
    eUAM_RightMiddle,               // 右中

    EF_UI_ALIGN_MODE_FORCE = 0xFF,
};
#define FUI_AM_LEFT_TOP             _FTW("左上")
#define FUI_AM_RIGHT_TOP            _FTW("右上")
#define FUI_AM_LEFT_BOTTOM          _FTW("左下")
#define FUI_AM_RIGHT_BOTTOM         _FTW("右下")
#define FUI_AM_MIDDLE               _FTW("正中")
#define FUI_AM_TOP_MIDDLE           _FTW("上中")
#define FUI_AM_BOTTOM_MIDDLE        _FTW("下中")
#define FUI_AM_LEFT_MIDDLE          _FTW("左中")
#define FUI_AM_RIGHT_MIDDLE         _FTW("右中")
#define FUI_AM_CONTROL_COMBO        _FTW("左上|右上|左下|右下|正中|上中|下中|左中|右中|")
extern FAPI BYTE FUI_AlignModeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_AlignModeByEnum(BYTE eAlignMode);


//----------------------------------------------------------------
// UI框架的工作模式
//----------------------------------------------------------------
enum EF_UI_WORK_MODE
{
    eUWM_Bottom           = 1<<0,   // 最低层
    eUWM_Normal           = 1<<1,   // 普通层
    eUWM_Exclusive_NoMode = 1<<2,   // 独占(仅显示自己，其它UI不显示)，且非模式
    eUWM_Top_Mode         = 1<<3,   // 置顶，且模式
    eUWM_Exclusive_Mode   = 1<<4,   // 独占，且模式
    eUWM_Top_NoMode       = 1<<5,   // 置顶，非模式

    eUWM_Has_Exclusive = eUWM_Exclusive_NoMode|eUWM_Exclusive_Mode,
    eUWM_Has_Mode = eUWM_Top_Mode|eUWM_Exclusive_Mode,
    eUWM_Has_Top = eUWM_Top_Mode|eUWM_Top_NoMode,

    EF_UI_WORK_MODE_FORCE = 0xFF,
};
#define FUI_WM_BOTTOM               _FTW("最低层")
#define FUI_WM_NORMAL               _FTW("普通层")
#define FUI_WM_EXCLUS_NOMODE        _FTW("独占(非模式)")
#define FUI_WM_TOP_MODE             _FTW("置顶(模式)")
#define FUI_WM_EXCLUS_MODE          _FTW("独占(模式)")
#define FUI_WM_TOP_NOMODE           _FTW("置顶(非模式)")
#define FUI_WM_COMBO                _FTW("最低层|普通层|独占(非模式)|置顶(模式)|独占(模式)|置顶(非模式)|")
extern FAPI BYTE FUI_WorkModeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_WorkModeByEnum(BYTE eWorkMode);


//----------------------------------------------------------------
// 文字的绘制模式
//----------------------------------------------------------------
enum EF_UI_TEXT_EFFECT_TYPE
{
    eUTET_Normal,                   // 普通
    eUTET_Shadow,                   // 阴隐
    eUTET_Fringe,                   // 描边

    EF_UI_TEXT_EFFECT_TYPE_FORCE = 0xFF,
};
#define FUI_TET_NORMAL              _FTW("普通")
#define FUI_TET_SHADOW              _FTW("阴影")
#define FUI_TET_FRINGE              _FTW("描边")
#define FUI_TET_COMBO               _FTW("普通|阴影|描边|")
extern FAPI BYTE FUI_TextEffectTypeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_TextEffectTypeByEnum(BYTE eTextEffect);


//----------------------------------------------------------------
// 控件的拖拽模式
//----------------------------------------------------------------
enum EF_UI_DRAG_MODE
{
    eURM_NoDrag           = 0,      // 无
    eURM_Single_In        = 1<<0,   // 只能拖进
    eURM_Single_Out       = 1<<1,   // 只能拖出
    eURM_Single_InOut     = 1<<2,   // 双向拖动

    eURM_CanIn = eURM_Single_In|eURM_Single_InOut,
    eURM_CanOut = eURM_Single_Out|eURM_Single_InOut,

    EF_UI_DRAG_MODE_FORCE = 0xFF,
};
#define FUI_RM_NO_DRAG              _FTW("禁用")
#define FUI_RM_SINGLE_IN            _FTW("允许拖进")
#define FUI_RM_SINGLE_OUT           _FTW("允许拖出")
#define FUI_RM_SINGLE_IN_ONT        _FTW("允许拖进拖出")
#define FUI_RM_COMBO                _FTW("禁用|允许拖进|允许拖出|允许拖进拖出|")
extern FAPI BYTE FUI_DragModeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_DragModeByEnum(BYTE eDragMode);


//----------------------------------------------------------------
// 框架的动画模式
//----------------------------------------------------------------
enum EF_UI_ANIMATE_MODE
{
    eUMM_No_Anim,
    eUMM_Transparent,               // 淡进淡出
    eUMM_AnimateScale,              // 动画缩放

    EF_UI_ANIMATE_MODE_FORCE = 0xFF,
};
#define FUI_MM_NO_ANIM              _FTW("无效果")
#define FUI_MM_TRANSPARENT          _FTW("淡进淡出")
#define FUI_MM_ANIMATESCALE         _FTW("动画缩放")
#define FUI_MM_COMBO                _FTW("无效果|淡进淡出|动画缩放|")
extern FAPI BYTE FUI_AnimModeByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_AnimModeByEnum(BYTE eAnimMode);


//----------------------------------------------------------------
// 控件类型
//----------------------------------------------------------------
enum EF_UI_WIDGET_TYPE
{
    eUWT_Unknown,
    eUWT_Frame,                     // 框架
    eUWT_Text,                      // 文本框
    eUWT_Picture,                   // 图片框
    eUWT_Edit,                      // 编辑框
    eUWT_Button,                    // 按钮
    eUWT_Check,                     // 复选框
    eUWT_Radio,                     // 单选框
    eUWT_ScrollBar,                 // 滚动条
    eUWT_ScrollBarEx,               // 扩展滚动条
    eUWT_List,                      // 列表框
    eUWT_Combo,                     // 组合框
    eUWT_Tree,                      // 树控件
    eUWT_Progress,                  // 进度条
    eUWT_ArrayGrid,                 // 阵列网格
    eUWT_Container,                 // 容器
    eUWT_Report,                    // 报表
    eUWT_RichEdit,                  // 多行编辑
    eUWT_Slider,                    // 滑条
    eUWT_SliderEx,                  // 扩展滑条
    eUWT_Rollup,                    // 卷集控件
    eUWT_ArrayGridEx,               // 扩展阵列网格

    eUWT_Count,                     // 控件类型总数

    eUWT_Config = 0xE0,             // 特殊类型，不属于控件
    eUWT_PreFont,
    eUWT_PreMenu,

    EF_UI_WIDGET_TYPE_FORCE = 0xFF,
};
#define FUI_WT_CLASS_NAME_UNKNOWN       _FTW("NULL")
#define FUI_WT_CLASS_NAME_FRAME         _FTW("FUI_Frame")
#define FUI_WT_CLASS_NAME_TEXT          _FTW("FUI_Text")
#define FUI_WT_CLASS_NAME_PICTURE       _FTW("FUI_Picture")
#define FUI_WT_CLASS_NAME_EDIT          _FTW("FUI_Edit")
#define FUI_WT_CLASS_NAME_BUTTON        _FTW("FUI_Button")
#define FUI_WT_CLASS_NAME_CHECK         _FTW("FUI_Check")
#define FUI_WT_CLASS_NAME_RADIO         _FTW("FUI_Radio")
#define FUI_WT_CLASS_NAME_SCROLLBAR     _FTW("FUI_ScrollBar")
#define FUI_WT_CLASS_NAME_SCROLLBAR_EX  _FTW("FUI_ScrollBarEx")
#define FUI_WT_CLASS_NAME_LIST          _FTW("FUI_List")
#define FUI_WT_CLASS_NAME_COMBO         _FTW("FUI_Combo")
#define FUI_WT_CLASS_NAME_TREE          _FTW("FUI_Tree")
#define FUI_WT_CLASS_NAME_PROGRESS      _FTW("FUI_Progress")
#define FUI_WT_CLASS_NAME_ARRAYGRID     _FTW("FUI_ArrayGrid")
#define FUI_WT_CLASS_NAME_CONTAINER     _FTW("FUI_Container")
#define FUI_WT_CLASS_NAME_REPORT        _FTW("FUI_Report")
#define FUI_WT_CLASS_NAME_RICHEDIT      _FTW("FUI_RichEdit")
#define FUI_WT_CLASS_NAME_SLIDER        _FTW("FUI_Slider")
#define FUI_WT_CLASS_NAME_SLIDER_EX     _FTW("FUI_SliderEx")
#define FUI_WT_CLASS_NAME_ROLLUP        _FTW("FUI_Rollup")
#define FUI_WT_CLASS_NAME_ARRAYGRID_EX  _FTW("FUI_ArrayGridEx")
extern FAPI const WCHAR* FUI_WidgetClassNameByEnum(BYTE eWidgetTypeID);
#define FUI_WT_UNKNOWN              _FTW("无")
#define FUI_WT_FRAME                _FTW("框架")
#define FUI_WT_TEXT                 _FTW("文本框")
#define FUI_WT_PICTURE              _FTW("图片框")
#define FUI_WT_EDIT                 _FTW("编辑框")
#define FUI_WT_BUTTON               _FTW("按钮")
#define FUI_WT_CHECK                _FTW("复选框")
#define FUI_WT_RADIO                _FTW("单选框")
#define FUI_WT_SCROLLBAR            _FTW("滚动条")
#define FUI_WT_SCROLLBAR_EX         _FTW("扩展滚动条")
#define FUI_WT_LIST                 _FTW("列表框")
#define FUI_WT_COMBO                _FTW("组合框")
#define FUI_WT_TREE                 _FTW("树控件")
#define FUI_WT_PROGRESS             _FTW("进度条")
#define FUI_WT_ARRAYGRID            _FTW("阵列网格")
#define FUI_WT_CONTAINER            _FTW("容器")
#define FUI_WT_REPORT               _FTW("报表")
#define FUI_WT_RICHEDIT             _FTW("多行编辑")
#define FUI_WT_SLIDER               _FTW("滑条")
#define FUI_WT_SLIDER_EX            _FTW("扩展滑条")
#define FUI_WT_ROLLUP               _FTW("卷集控件")
#define FUI_WT_ARRAYGRID_EX         _FTW("扩展阵列网格")
#define FUI_WT_CONTROL_COMBO        _FTW("无|框架|文本框|图片框|按钮|复选框|单选框|滚动条|扩展滚动条|编辑框|列表框|组合框|树控件|进度条|阵列网格|标签|报表|多行编辑|滑条|扩展滑条|卷集控件|扩展阵列网格|")
extern FAPI BYTE FUI_WidgetTypeIDByName(const WCHAR* strName);
extern FAPI const WCHAR* FUI_WidgetTypeIDByEnum(BYTE eWidgetTypeID);


//----------------------------------------------------------------
// 控件的事件传递信号值，并不是所有的事件信号返回值都有用，同时不是所的的控件在传递该事件的时候返回值有用。
//----------------------------------------------------------------
enum EF_UI_EVENT_TYPE
{
    eUET_Unknown,
    eUET_LButtonDown,               // 左键按下         (wParam = mX, lParam = mY)
    eUET_LButtonUp,                 // 左键弹起         (wParam = mX, lParam = mY)
    eUET_RButtonDown,               // 右键按下         (wParam = mX, lParam = mY)
    eUET_RButtonUp,                 // 右键弹起         (wParam = mX, lParam = mY)
    eUET_LButtonDouble,             // 左键双击         (wParam = mX, lParam = mY)
    eUET_RButtonDouble,             // 右键双击         (wParam = mX, lParam = mY)
    eUET_DragIn,                    // 拖拽进入         (wParam = 源 nFrameID, lParam = 源 nWidgetID)
    eUET_DragOut,                   // 拖拽拖出         (wParam = 自己 nFrameID, lParam = 自己 nWidgetID)
    eUET_DragThrow,                 // 拖拽丢弃         (wParam = 自己 nFrameID, lParam = 自己 nWidgetID)
    eUET_GetFocus,                  // 获得焦点         (无参)
    eUET_LostFocus,                 // 失去焦点         (无参)
    eUET_KeyDown,                   // 键盘按下         (wParam = 键码)
    eUET_KeyUp,                     // 键盘弹起         (wParam = 键码)
    eUET_KeyChar,                   // 字符输入         (wParam = 键码)
    eUET_MouseIn,                   // 鼠标进入UI       (无参)
    eUET_MouseOut,                  // 鼠标离开UI       (无参)
    eUET_ScrollPosition,            // 滚动条位置改变   (wParam = 当前位置)
    eUET_ProgressPosition,          // 进度条位置改变   (wParam = 百分比)
    eUET_MenuCall,                  // 菜单调用         (wParam = 菜单ID)
    eUET_CheckChange,               // 复选框选中事件，或者单选框单击事件 (wParam = 选中状态)
    eUET_ComboChange,               // 组合框选中了一条数据 (无参)
    eUET_ListSelect,                // 列表控件选中     (wParam = 索引, lParam = FU_LT_ITEM*)
    eUET_ReportSelect,              // 报表控件选中     (wParam = 索引, lParam = FU_RT_LINE*)
    eUET_TreeSelect,                // 树项选中         (wParam = 0, lParam = FU_TR_ITEM*)
    eUET_TabSelect,                 // 标签选中         (wParam = 0, lParam = FUI_Container::TAB_DATA*)
    eUET_GridSelect,                // 网格的选中事件   (wParam = y, lParam = x)
    eUET_SliderChange,              // 滑条滑动事件     (wParam = 当前位置)
    eUET_MoveTo,                    // 对象被移动       (无参)
    eUET_MouseWheel,                // 滚轮事件         (wParam = 是否是上滚)
    eUET_RollupSelect,              // 卷集项被选中     (wParam = 0, lParam = FU_RU_ITEM*)
    eUET_FrameLayer,                // 框架层次改变     (wParam = 是否进入顶层)
    eUET_ReportHeadWidth,           // 报表头尺寸变化   (wParam = 新宽度, lParam = 有变化的头索引/-1表示更新整个头宽度)

    eUET_User = 0x800,              // 用户消息事件ID开始

    EF_UI_EVENT_TYPE_FORCE = 0xFFFFFFFF,
};


//----------------------------------------------------------------
// 
//----------------------------------------------------------------
enum EF_UI_TEXTURE_SAMPLE_MODE
{
    eUTS_Liner      = 1<<0,
    eUTS_BlendOne   = 1<<1,

    EF_UI_TEXTURE_SAMPLE_MODE_FORCE    = 0xFF,
};


//----------------------------------------------------------------
// 1.控件的图片和文字是分开绘制的
// 2.组合框的下拉列表和组合框控件本身是分开绘制的
//----------------------------------------------------------------
enum EF_UI_RENDER_LAYER
{
    eURL_BackPic,       // 仅画控件的背景图片
    eURL_Picture,       // 仅画控件图片，除背景图片以外的其它图片，除内嵌滚动条控件（如果是组合框，不要处理它的下拉列表）
    eURL_InsideScroll,  // 画有内嵌滚动条的控件图片，不是背景图片
    eURL_Text,          // 仅画控件文字
    eURL_EditBlock,     // 画编辑框、多行编辑框的选中区域块
    eURL_ComboList_Pic, // 组合框的下拉列表图片
    eURL_ComboList_Txt, // 组合框的下拉列表文字

    EF_UI_RENDER_LAYER_FORCE    = 0xFF,
};



//----------------------------------------------------------------
// inline
//----------------------------------------------------------------
FINLINE WCHAR FUI_ConvertCharW(WCHAR k, BYTE cov_type)
{
    if (cov_type == 1)
    {
        if (k >= _FTW('A') && k <= _FTW('Z'))
            return k - _FTW('A') + _FTW('a');
    }
    else if (cov_type == 2)
    {
        if (k >= _FTW('a') && k <= _FTW('z'))
            return k - _FTW('a') + _FTW('A');
    }
    return k;
}

FINLINE ACHAR FUI_ConvertCharA(ACHAR k, BYTE cov_type)
{
    if (cov_type == 1)
    {
        if (k >= _FTA('A') && k <= _FTA('Z'))
            return k - _FTA('A') + _FTA('a');
    }
    else if (cov_type == 2)
    {
        if (k >= _FTA('a') && k <= _FTA('z'))
            return k - _FTA('a') + _FTA('A');
    }
    return k;
}


//----------------------------------------------------------------
//
//----------------------------------------------------------------
#ifdef UNICODE
#define FUI_FileNamePosition    FUI_FileNamePositionW
#define FUI_GetHash             FUI_GetHashW
#define FUI_GetIDByString       FUI_GetIDByStringW
#define FUI_StringFmt           FUI_StringFmtW
#define FUI_OutDebugString      FUI_OutDebugStringW
#define FUI_MakeDirectory       FUI_MakeDirectoryW
#define FUI_Strcpy_s            FUI_StrcpyW_s
#define FUI_Stricmp             FUI_StricmpW
#define FUI_Strlen              FUI_StrlenW
#define FUI_Atoi                FUI_AtoiW
#define FUI_Strcpy              FUI_StrcpyW
#else
#define FUI_FileNamePosition    FUI_FileNamePositionA
#define FUI_GetHash             FUI_GetHashA
#define FUI_GetIDByString       FUI_GetIDByStringA
#define FUI_StringFmt           FUI_StringFmtA
#define FUI_OutDebugString      FUI_OutDebugStringA
#define FUI_MakeDirectory       FUI_MakeDirectoryA
#define FUI_Strcpy_s            FUI_StrcpyA_s
#define FUI_Stricmp             FUI_StricmpA
#define FUI_Strlen              FUI_StrlenA
#define FUI_Atoi                FUI_AtoiA
#define FUI_Strcpy              FUI_StrcpyA
#endif

#ifdef WIN32
#define FFUI_FileNamePosition   FUI_FileNamePositionW
#define FFUI_GetHash            FUI_GetHashW
#define FFUI_GetIDByString      FUI_GetIDByStringW
#define FFUI_StringFmt          FUI_StringFmtW
#define FFUI_OutDebugString     FUI_OutDebugStringW
#define FFUI_MakeDirectory      FUI_MakeDirectoryW
#define FUI_Strcpy_s            FUI_StrcpyW_s
#define FUI_Stricmp             FUI_StricmpW
#define FUI_Strlen              FUI_StrlenW
#define FUI_Atoi                FUI_AtoiW
#define FUI_Strcpy              FUI_StrcpyW
#else
#define FFUI_FileNamePosition   FUI_FileNamePositionA
#define FFUI_GetHash            FUI_GetHashA
#define FFUI_GetIDByString      FUI_GetIDByStringA
#define FFUI_StringFmt          FUI_StringFmtA
#define FFUI_OutDebugString     FUI_OutDebugStringA
#define FFUI_MakeDirectory      FUI_MakeDirectoryA
#define FUI_Strcpy_s            FUI_StrcpyA_s
#define FUI_Stricmp             FUI_StricmpA
#define FUI_Strlen              FUI_StrlenA
#define FUI_Atoi                FUI_AtoiA
#define FUI_Strcpy              FUI_StrcpyA
#endif